package com.yaorange.api;

import com.yaorange.common.core.domain.AjaxResult;
import com.yaorange.nongjt.domain.NjtUserRegister;
import com.yaorange.nongjt.service.INjtUserRegisterService;
import com.yaorange.nongjt.vo.NjtUserRegisterVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(value = " 会员管理 ", tags = " 会员管理 ")
@RestController
@RequestMapping("/api/user")
public class NjtUserAPI {
    @Autowired
    private INjtUserRegisterService userRegisterService;
    /**
     *
     *
     校验⼿机号是否可以被注册
     * @param mobilePhone
    注册⼿机号
     * @return
     */
    @ApiOperation(" 校验⼿机号是否可以被注册 ")
    @ApiImplicitParam(name = "mobilePhone", value = "注册⼿机号", required = true, dataType = "String")
    @GetMapping("/checkMobilePhone")
    public AjaxResult checkMobilePhone(@RequestParam("mobilePhone") String
                                               mobilePhone) {
        NjtUserRegister userRegister = userRegisterService.getByMobilePhone(mobilePhone);
        if (null != userRegister) {
            return AjaxResult.error(" 该⼿机号已被注册, 请更换注册⼿机号 ");
        }
        return AjaxResult.success("⼿机号可⽤ ");
    }

    /**
     *
     会员注册
     *
     * @param registerVO
     * @return
     */
//    @ApiOperation(" 会员注册 ")
//    @PostMapping("/register")
//    public AjaxResult register(@Valid @RequestBody NjtUserRegisterVO registerVO) {
//            String mobilePhone = registerVO.getMobilePhone();
//            String password = registerVO.getPassword();
//            String checkCode = registerVO.getCheckCode();
//            //⽐对验证码是否⼀致
//            String code = redisCache.getCacheObject(CacheConstants.VALIDATE_PREFIX
//            + mobilePhone);
//            if (!checkCode.equals(code)) {
//            return AjaxResult.error(" 验证码有误 ");
//            }
//            //保存注册信息
//        return userRegisterService.saveRegister(mobilePhone, password);
//    }
}

